Fix type and a logical error