first working version. no extensive checks done yet