First draft version. Works ok.