Added extra checks from @tunixman