refactor and fix
searching using js