added improved function