MAIN subroutine