Updated to use Entities. Still work in progress.