Refactoring and improvrd performance