API changes

Changed and improved API, improved selftests