Factor out functionality into separate files