first working version(very  buggy)