Moved year variable outside loop