Cleanup and bug detection in environment_free.
Merge pull request #29 from minad/env_cleanup

Cleanup and bug detection in environment_free.