cleaned up code and added equals method