[notes] Refactor.

Move the directory match into a seperate function as it is done more than once