Refactor: Optimize ANSI-Escape functions and move util function definition to separate file