Modularized library functions, and implemented some tests.
Added travis setting.