nit: Please move the following code up.  
```
} else {
...
}
```