fixing advanceN (almost complete)