Improve filling algorithm