refactored everything; now in a working state