datastore: refactor transaction & datastore.

Hello again!

I rearranged a few things, hopefully for the better. I'll leave comments. :)
This was refactored for testability - `dataset.createTransaction()` will return a new instance of Transaction. This was added to allow stubbing of "addTransaction" in the tests.