When working on revamping on old existing code base, things to consider so that it doesn't make your life hard later on :
This is to determine the effect your code changes is gona make to other modules in beforehand. This will help to plan the workflow, divide work in small batch and finally determine time required for the revamp.
This is the meat you are going to spend most of your time .Normally discuss it with team members on ways to write clean and modular code.It is important you follow best practices SOLID so that you wont go "WTF" the very next month after you made changes. Documenting the changes as to share with team members and fo future reference.
This is the fruit that is expected after all the hard work and time spend on above two points. Existing bottlenecks can be determined in impact analysis / study phase , so the end result must be like how you solved the bottlenecks. ie. before - row by row db insertion, after bulk insertion.
Using "and" and "or" in programming
#AND (condition that is highly likely to be false is place at front) cond and cond and cond #OR (condition that is highly likely to be true is place at front) cond or cond or cond