Add function 'end's, fix a variable name