restructure to make code readable