Almost done but not tested.
buggy