Code, tests and API cleanup