Wrote functions for assignment 2