Implementation of both necessary functions