Added more detailed comments and fixes