Refactor command line handling