working. but needs refactoring