Fix for #40
Better dirty check