API and cleaned things up a bit