Refactor options logic out to general lib