Added more checks for safety and user-friendliness