* refactor from older PR, add test coverage * PEP8, consistency * clarifying comments * more concise * consistency