fix bugs to get it working better

Still some left though.