Dry'ed up code
completed error handling