Changed back to global variable, have not found anything suitable for this purpose yet