added extra checks to avoid issue #5