initial working version, still some bugs