Fix a few potential memory leaks

Some events weren't being unregistered, midi wasn't entirely removing
data... fixed to help preserve memory on servers that are left running
for very long periods.
Add 'foreach/repeat stop' command

You can now force a foreach / repeat loop to stop mid-execution!
Not sure if this is the best implementation, but it works (and fairly
efficiently too)