added api, cleaned up code