enhance code and add documentation