Generalize code for systems larger than H2. Not working properly.