first working version, with tests