A better implementation of the javascript