Assignment 2 implemenation.