changes code to be more stable