Fixed return values and fix API adherence and few bug fixes