Better border logic for alerts. General refactoring.