You've got a few places where inconsistent indentation makes it harder to read your code. This function is the worst offender, but there are some let blocks further on that have odd spacing.