split out directive specific functionality out of main controller