Various performance fixes