removed selected nodes logic and increased readability for the code