Better code organization

I implemented the changes mentioned in the previous commit message and
moved some messy code to a subfunction, compositeDelays. This is also an
improvement because we may want to change the delay structure in the
future, and it'll be easier to change it in just one function.