Major files refactor; may contain bugs!