added more server-side and client-side error handling.