Initial fix, almost done minus one bug