Reorganize, clean up, format code