Added more checking logic