Added function definitions and comments