Code clean-up

Very little changes just moving a few lines around