Improved error handling and removed the unnecessary local jQuery