Improved the patch! This should be close to the final behaviour