Fix for type null and refactor (removed compareTo where not needed)