Improve detecting of localStorage

Should fix #245.