still refactoring, but slowly getting somewhere