Refactoring

Some basic refactoring