adding safety checking