Fixed a few minor bugs, seems to work nicely now and is a bit faster than before.