API improvements and code cleanup