Refactor and improved preferences