Fixing bug that causes bad access exception