Extracted code into methods.  Added tests for these methods