Fixed bug: used var before defined