Performance improvements

• Fixed major memory leak
• Reduced latency by up to 50% (in rare cases only, usually about 1%)