Changed function form to match R style guidelines