Added the main code

Added the main code. Cleaning and comments are still needed.