Code refactoring, sync with ampcontrol.