Implement tables

Re-implemented code using tables