Optimization code um pythonic way.