Misc. fixes, performance improvements