refactor directory
made things more modular and fixed some bugs along the way