Refactor compex entity code into multiple methods for readability.