Functions for the Coursera 2nd Assingment