refactor/improve dirty handling
fix segfault on opening empty file