Code refactoring

close #45