Refactoring api options array, making setOptions generic. Rebasing #227