refactored a lot, buggy atm