Refactor options and bug fixes