Removed ~ files, and refactored code