Remove username global variable by placing it in function