sort: Rewrite to avoid repetitive code
sort: Add type signature for main