Based in part on work from PR #21 by @Sai-Prashanth123, adapted and integrated with project-specific fixes.