Assignment #2 implementation for cs107