Improved deploy function