removed .bak files and refactored the code