Fix some dumb mistakes
Still a work in progress...
Fix to remoteapi ended event handler