fix 2pass index bug
Implement delayed closing of ressources

closes #34