code merge with Will Farmer's changes