ak improved code and added documentation