tidied code and improved Search