Env tests

A few mistakes were present; fix them and introduce tests.