split into modules (first pass)
further refactoring