Cleaned up tests to use withenv, added some code comments