Fix if clause, instanceof always returns false is object is null
Fix equals method to check correct class