corrected afterId method in the factory