algorithm bugfix