Cleaned up tmp directory lookup process. Also moved setting of LOADED_EMBEDDED_LIBRARY down to where it belongs (the bottom).