Refactoring for better handling of multiple commands