Finalising of the task. Works correctly for small and big datasets