Removed global variable and used function attributes