general refactoring; move more stuff to methods