small fixes, made som stuff more pythonic, reorganized helpers