Added more comments and function headers