import later changes from my perl improve_storage branch