reverted most of the changes from previous commit while keeping good ones

does not pass all tests yet