Adding loops and functions