Add nan protection and re-introduce compartment sampling