Reorganize the code, make it clearer