Changed behavior so that error is only printed after function is called