some fixes. Thanks bakfitty for the patch