Refactor and add tests to Alert class