works from first look, no tests, no ui, needs refactoring