Created a bit more general detection functions.