first working version, still some work to be done