edited js file a little for better error handling