New version with some refactoring of the main.m script