added benchmark mode, various performance fixes