some refactoring and fixing small bug in generating imports