Fix stages sometimes not saving properly in the database