Refined code

Added more comments.