Improved sub command handling