added some security checks