Api style and some minor bug fixes