extracted detect palm function
cleanups