re-order code for better orginization