Replacing Dialog with DialogFragment and fixing tests

And a few other minor bugfixes.