implementation (a little bit worked, still buggy...)