Refactor

Some basic refactoring