working version with reorganized python modules. needs unit testing.