Search functionality, heavy refactor of JS