re-arranged code