refactored command parsing