simplified some parts and fixed a bunch of bugs