Refactored some files and started tests.