some improvements by jsmeix