cleaned up a bit, added upset detection