Your "end"s look untidy and the indentation should be tidied up.
You may have one too many/in the wrong place?