Refactored code.
Fixed files for merge.