Fixed search function so it no longer throws exception, not fully tested because tables are empty