moving functions from bookmarklet