improved function organization