Optimized code and fixed typos.
Now the user set a preference, fallback method will be used.