found another bug, there was a logical mistake using MAX instead of MIN