refactoring functions, removing unnecessary nodes