Added tests for entities and controllers, fixed some found issues

This PR comes with some tests for the controller classes and small fixes for problems found in testing.
Added hook to improve testability