Fix bugs, improve formatting, add specs.