Stylistic improvements and bug fixes