Clipboard fixes

Clipboard is still having problems. This commit should help to avoid crashes line the one reported in issue #411