Corrected loop error in equals and hash method