Refactored to make class more modular.