Make main() callable from API
Add tests for main