Fixed bugs and added more documentation