added commecnts
added test, fixed many bugs