adding missing "do", indenting lines and adding "end"