Function modified to fulfil requirements as per Programming
assignment 2.