cleaned API and restructured code