Added options for different sampling modes, runs with out segfaults, needs tests.