Fix processing bugs. Refactor a bit. Basically finish