fix bug #10, move copy routines to common code and minor improvements