Refactored entity functionality into separate module.