Bug in calculate range