Removed unnecessary clauses, and added safer checks