Apply patch from Toomas Kiisk <vix@cyber.ee> and complete it.