Code for assignment 2b