Major refactoring and decoupling. Dialog added for searches.