Fixed all review comments except moving the code from search.js to metrics.js