a little bit of refactoring, need to flesh out more