moved bestInPlace to javascript file