Little bit of styling and moved code from loop to individual functions