clean up, fix and test env handling