implemented multiple users/units, reorganized code