Fix obvious bugs (still not tested)