You might find Chapter 8 of this book helpful:
http://www.chiefdelphi.com/forums/showpost.php?p=1308755&postcount=18
It has not been revised for the 2014 code yet, but there are not huge changes. You should be able to sort it out. (Revisions to match 2014 should be posted in less than a week.)