bit polished initial version completely pythonic