fixed undefined variable at beginning