Fix the calculating logic for input region