Fix variables undefined issue