basename.go: Improve readability

Instead of one giant glob of code in the main function, I have split it up into simple functions.