added copyright; made platform independent; some refinement