Refactoring tablet code