Implement paste functionality

Based on work by Nick Ashley and Eugene Golendukhin