Removed debug code, fixed formatting and added comments