Fixing code, adding doc