upgraded code to be more pythonic!