Some refactoring. Still not satisfied.