Fixed a bug in the findAfterInstances function