Edited script: finding functionality moved to separate function