added ajax loader and improved error handling