begin main ui code and ffi stuff