some cleanup of the realm logic