fixed nan problems with loc