fix variable referenced before defined error