Bug fixes, reformat