Fixed a few bugs and improved the style slightly