reduced code and refactored - sub 400 lines