Removed duplicated code.

Pulled out duplicated code into 'helper' methods.