Fix passenger-ami command and do some refactoring.