refactor and prep for gui