clean version. fixed minor bugs and merge conflicts