Bug fixes for bug #642