refactor some code to make everything work now