Improved detection end of function
Clean up indents