Refactoring detect and orientation functions to separate detection from class appending