updated code and added documentation