Some useful functions written in JavaScript