Debugged and added more comments