Updated javascript to have more unique variable names
Added closeConnection() function