update

I've fixed some logical problems and noticed other.