added table functionality and refactored code