Added function to update previous states