some more refactoring; code is... now remotely readable, hopefully.