Simplify overengineered code
Merge pull request #3470 from Dmitry-Me:simplifyOverengineeredCode