Fixed a deadlock occuring because of wrong condition and added left out comments