Fixed bugs and added documentation