First version, sort of works most of the time.