Updated with new API and cleanup