refactor code into multiple files

this code is in an unknown state.