Refactored file. Still incomplete