init commit

The previous lib was written in a hurry.
This is the first init after refactor.