Equals and hashcode, plus refactoring