working solution, needs refactoring