fixed bugs, made functions more modular, removed unnecessary files