Cleanup and format code