rearranging the code, structure and functions