using global vars slows down the program