Refactoring changes

Added equals and hashCode methods.
Added unit test cases.
Refactored most methods to be more object-oriented.