api stuffs and a few bug fixes