Added MARKs and reorganized code