Fixed code style issues and added comments