cleaning python subroutines