Added unmodified code from www.menie.org.