Lots of fixes and added API