cleaning up JavaScript code and fixing bugs in graph view on click