Wrote functions and added comments