Created functions and added comments