Using singleton instead of a global variable