Working implementation of the assignment 2