Refined the code and updated the documentation.