Implementation for assignment 2