Removed unnecessary undirected structure and merged ifs