@done: working jajascript solution, may need to optimize