Refactored some redundant code and add sfw option