finalized code, missing comments