Some style and bug fixes