Added api functionality

- Lots of bug fixes