commented function code to make easier to understand