Cleanup and reformat code