Various API improvements and debugging