Fixed event cancellation bug; misc refactoring.