bugs removed, changed the api and improved performance