changed code to a pythonic way