Almost working ksh version