refactoring and fix argument swapping
more refactoring
even more refactoring