Derived from Ilan E. Moyer's corexy implementation, corexy.com.