Refactoring in progress. Not working version.