Refactor and add unit test to env.lookup