Removed unused code. Also fixed logic.