Optimized source code and added some comments.