Fixes crash on switching to search tab, cleans up code.
Merge remote-tracking branch 'origin/master'