added settings options and refactored the code