Several performance fixes