some fixes from the stack overflow