moved local func up top