fix terminator detection