Tidy up of hipsr_server.py

Added loops over keys to tidy up the code and make it easier to maintain.