Improved version with support for clipboard