update to new API and improve structure