Cleaning

Added regions and more comments to make the code more structured.