Update gethead.py

added some checks and moved all test to their own defined function