Allow configureable repeat, refactor with tests

also add run_tests.sh and travis