Added debug info, fixed a bunch of bugs, added some optimization. WIP