Cleaned the code and add main.