Updated logic.

Based on https://github.com/blackberry/BB10-WebWorks-Samples/issues/212#issuecomment-34217828