Removed debug code and added some comments for clarification