sort functions by semantic
update final code