Added short-circuit conditions to prevent Index Errors in the process_commands function.