Revised fix based on dfoster's comments.