Removed bugs and added documentation