NPE fix in molecular formula manipulator

First patch highlights the issue; the second patch provides a fix.