Fixed some issues and added comments