BUG: fixed varaible not assigned in some cases