Refactoring and clean up. version 1.0.2