functions and tests for both step1 and step2

I started working on part 2 prior to submitting part 1 and so have included both portions in the same pull request. Hope that's alright, thanks.