Fixed bugs found during benchmark tests