added entities and converted some queries