Rework command API and main function handling.