moving declarations closer to their use