port everything to environ and cleanup code