cnd is now an option
splitted the code in more logical units