Minor clean up, reordering of code