Datastore fixes and updates

There is an issue that raises exceptions in the datastore that will be fixed by this pull request. This pull request also includes the changes from 2733 that are a few months old.

Fixes #246 

Requires #248 to me merged to make all tests pass.