Merged Michael's changes into Jim's code