Updated code to match documentation (nearly)