Big refactor and cleanup some files