Tray.ai Interview Question

Refactor this code in a readable and future-prone way