Modify details to criteria function to prevent undefined variable errors

Also improves function readability.
Add tests for Alert class.