last pull request had major flaws which broke lots of things. rolled back to here, and fixed bugs