Fixed a few more issues, some optimizations