Refactored code, in preparation for Chapter 4

Signed-off-by: Elliot Voris <elliotfriend@gmail.com>