move location check to function, all-else failed exception