check things exist before using them + fixed an exception throwing