added missing check for subroutine exit code