more pythonic way of doing this