bug fix, efficiency improvements and API tweaks