refactor and code clean-up