Remaining changes to control condition

These are the changes made to the control condition after the first pull request.
Also, it looks like there's a lot of code that you've written over and over again here. Should you abstract that out into smaller functions?