Changing implementation to pure js.