Cleaning this up by moving into separate files