Moved some helper functions to NGram.