Better JavaScript handling for return method