fix creating user reference when case sharing is enabled

also a bit of cleanup