Major code cleanup, fixed condition where EnvSetMapApperance has a wrongly cast type