algorthm bugfix