refactoring using functional and table-driven method