Fixing bugs and improving documentation