Fixed Realm related issues

- Maybe. I was never actually able to reproduce the crashes, but I at
  least made the Realm stuff a bit more idiomatic, which should
  hopefully fix the problems.
2 jobs for master in 2 minutes and 57 seconds
Status Name Job ID Coverage
  Build
failed build #2838

00:02:57

 
  Test
skipped unitTests #2839
 
Name Stage Failure
failed
build Build There is an unknown failure, please try again
> Crashlytics Developer Tools error.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.

BUILD FAILED

Total time: 51.819 secs
ERROR: Job failed: exit code 1