bug fixes & error handling