Fixes bugs and formatting