Fixed bug in takeWhile
Redid the ensureNoteIntegrity function because it was causing several issues.