added more comments and before each function