Fixed several bugs related to database references. Also added unit tests to verify several components.
Fixing models