Bug fixes, internal funcs, cmds and API