Refactoring and fixes for linux WRT.