controller refactoring including support for tables