Fixed some issues and added some comments