Code refactoring and optimize imports