Extract duplicate code to single method.
Reduce scope of methods.

Closes #384