Replacing alerts, cleaning up code