Moving error handling out to it's own method