Some cleanups, also speeds sboget up a bit.