Added missing `end` to `if`. Fixes #311