Bug fixes and minor api changes