Rewrite program with begin