Refactor and fix.