First full implementation of the 2 functions