Final code for assignment