Added boundary checks to all public API functions