Added two modes: sub and main