Fixed unresolved issue from previous commit, added extra safety measures