its disgustingly ugly, but it works
bob in javascript