refactor file logic into models to prepare for API, minor touches.