Made some changes for the bugs, haven't had time to test. The changes probably don't do much anyway.