Original code by Eric Swan.