added doc comments, code formatting