Assignment 5 implementation