Add some comments and clean code