Optimize uninstall function