Some API changes and bug fixes