Cleaning up environment processing code

adding methods to reduce code redundancy