remove unnecessary nodes