moved some code into its own files