re-arrange

moved some code around