More bug fixes, cleanup of tmp dir