Refactor large blocks and clean up code

Signed-off-by: Derek McGowan <derek@mcgstyle.net>