Add additional check of existence of environment before erasing it

Change-Id: I0f73e8e064d13b1dbacc19c7bfad6a1a0b0d80e1
Closes-Bug: #1371496
Merge "Add additional check of existence of environment before erasing it"