Completed the assignment with some code cleanup