Hello @Altenbach,
Thank you so much for your useful tips. It's such a blessing to learn from the people like you in the community.
As a result of your tip, the code has become much more efficient. I'm adding the latest version of the code here for learning purpose. Also, if you find something can be improved in the code or my coding practice, do suggest. I appreciate your suggestions.
Thank you