Refactor to make everything use entities