Updated code as of 7/21/2013, post-competition.