fix logic for require_environment

Fixes #961
bug report (and an awesome one at that)
Merge branch 'issue-961' into devel