Incorporating two changes.

- using the lastIndexOf for the END string, originally noted by user github.com/1999

- adding a condition check on the typeof around line 260, that was causing an error when a number of requests was hitting memcache.