Fixed error handling in the name search and tidied things up a bit.