using the apply function to tidy up the syntax