fixes from nickplee fork