Simplified and fixed implementation of copyMessages (fixes #541)