Improved function.