Refactored file structure and fixed minor bug