Refactor part1

Refactored the first five functions or so