Clipboard fixes

Clipboard is still having problems. This commit should help to avoid crashes line the one reported in issue #411
Merge pull request #415 from giox069/master

Clipboard fixes