Improved bootstrap function