wip + minor refactoring.