Fix possible NULL dereference.
Fix memory leaks and possible NULL pointer dereference in pay_from_container().
Fix _technically_ possible division by zero.