Removed commented code and fixed flow logic