modified for loops to use range where possible, go fmt