Added assertion to prevent a potential integer overflow
Made some arguments const
Formatting