Move main stuff to main
Refactored for easier testing (including changing the arguments), made some tests