modified source environment function & other improvements