Fix memleak and format appply_like_update
Cleanup and standardize apply_update