Fixed Javascript TypeError