part of tk1 code copied