Fixed checkEmpty to work for all cases.