Add detailed comments and API documentation