The same code is copy pasted so many times.... It becomes obvious that it requires some better modularization, so that we have it in one place only and is just called from various places. Incorrect design.