moved around functions for legibility