added jquery and cleaned syntax
added error handling