added selection rect, fixed division by zero