Some refactoring and added settings directive