Fix some issues with commands and events, add basic tests for them