added options and refactored some code