Improved function