added more comments and function prototypes