restructured API, improved validation