refactor code, more pythonic :)