refactored clipboard code