Finished the assignment, needs some refactoring.