Refactored into multiple files
Minor fixes