updated code to be stable