issue #8: added safety check