First version, copied much code from cashcow.