Added more error handling checks and data checks