Refactored ES code for readability and ease of testing. Trying to fix firefox svg error