Fix taking head of empty list

Keep tor on when we're doing the Conf step so we can serialize it and use it
in the rebase --continue step.
Clean up code

Remove comments
Put types at the start of the file
Fix indentation
Move test functions to Test.hs