Added API. Updated all commands and events to use it.