Fixing parallel issue with environments and making unit test more robust