About the issue with 0. Please put a source code comment here. (as you commented: "Usually we use pdf in log-domain and the log_sum trick to avoid numerical underflow in particular for IID samples.")
Such comments are very helpful later on