Refactoring to implement Template Pattern and increase code reuse a bit.