made error handling throughout the Security layer more consistent