First version that seems to work.