in reply to Help with finding the wrong code

It sounds like you did not have a repository to roll back the last changes from. That would be a good idea in the future.

It also sounds like you can't trust the existing code base even aside from the errors.

Perhaps it would be best to do a rewrite, using the old scripts only as reference?