updated code and it seemms to be pretty stable