Fixed more bugs caused by wrong assumptions of how mongoose works. Added more tests