Fixed bugs, added documentation