Add some comments, use sprintf() with  and some other minor changes