Table code refactoring, added comments