Removed unnecessary headers
Small optimization in calculation of P
Renamed L to S (because it is called so in research paper)
Replaced function call with it's code

This function is called very very often. Replacing function call with
it's code gave noticable acceleration.
Removed unused function
Replaced function call with it's code in calculation of P
Clarification
Clarification