WIP: restructuring to make more testabul