Added entity class, cleaned up code