Alert formatting and code refactoring