Bug 199v3

Updated this pull request to make it easily merge with current master.