major performance re-write