Improved level_end and added comments