Replaced sum() with an explicit loop.
Fixed getopts() call.