first more or less working version. issue #3