fixed memory leak in L&R calculation, gave minor speed improvement
Switched to use memset where possible in L&R