Reorganized the flow of code, tested and debugged.