Add 'end' to function and fix indent