cleaned up working javascript