Simplified and fixed this logic
Fix for removal
Revert "Simplified and fixed this logic"

This reverts commit df312f72ee883e6c6328caa8368178e46b98d172.

This fix does not work like expected