Clean up and optimized plugin initialization code.