Changed to a slower but stabler margin algorithm