Break out pieces into headers; minor refactoring