changed the order of lines because variables has to be defined before it is used