Tweaked algorithm and alertbox