functions defined and comments added