Fix env module and implement tests.