Better environment handling & code optimization