Refactor constants and formatting code