moved code to directive