changed source function to an array (instead of a function) and fixed a related index error in the formal solution