fixed swda.py file again
Removed unnecessarily nested functions for clarity