fixed bug where variable wasn't set at the right time.