Simplified codes with __import__ function and some other minor refactoring.