re-organizing code for legibility