Fixed mismatched dimensions issue and NPE