Code improved, and added some comment