Reorganise code for PEP8