fixed a bug in detecting first run