added defense to algorithm