Fixes lots of bugs, other little API improvements