a fix for after_write infinite loop. could be costly though