Apply the patch from Jose

This patch adds fill functions based on the quality and simplifies
the sampling