Add useful comments, clean up the code