Moved some functions into formatting.py (utils.py is too long)