finalized v1.0 code