Reorganize and format code for readability