Added error handling for invalid width or height value