Ported main code
Ported test suite