Add functions to util2d to make it more generic and versatile