added error catching for subs