Added error checking to task method