first working version (some bugs exists)