Adding implementation and comments for the functions