fixed some bugs, for some reason the output still isn't reliable