working, but needs refactor