breaking out some logic into directive