Refactoring. Need to test it.