more refactoring. splitting up common stuff into files.