added writing to env variable, worked out some kinks, but not all