Fix issues where undefined variable was used