Completed FirstPass algorithm