Refactor complex methods checkin and checkout (#666)

As per #666. **This pull request is not to be merged yet, as it is lacking test coverage.** Review solicited, since the operations on the methods' internal logic are over.
Agreed, we should be able to streamline this a bit. I'll mess around after I review the rest of the code.