Some table and code refactoring