Reorganize lib, make more consistent
The library interface isn't very good or consistent, it should be refactored to a better standard.
Changes that may be beneficial:
- splitting into multiple files
- function renames
- more strict types in function signatures
- a proper naming convention