Merged Grahams code