Assignment 2 functional code