changed variable 'type' to 'mode' to be more accurate