add error handling code, and bug fixes for screenshot capture feature