Use localStorage instead of local variables
Replace synchronous returns with deferreds