improves search function, cleans up js