first working version (ugly but working)