ALL COMMENTED apart from three functions