refactored code and prepared for port to local dev