BUG: fixed variable declaration before referencing