This is what was messing up my most recent project.
I completely stole this from Gary Bernhardt. But it's a start.