factored some code into protected functions so they can be overridden in subclasses