Fixes #2 Sets $first flag at proper time in the code