Quick fix to algorithm