Clean up existing Java Script code

Updated the existing code to modularize into functions and call them
where needed. Also added comments on what each function does.
Search feature working

Linked the resulting table data with the search feature.