Wrote takeSamples() and auxiliary functions

Wrote takeSamples() and auxiliary functions, also gave the code some
more structure.