modularized, made sampling uniform, added performance todo