added documentation & cleaned code