changed equals method to avoid null pointer exception