fix: assign result of function to variable before accessing it