some bug fixes with some new comments and new formatting style