Reorganize code into multiple files
Fix tilde expansion