Refactoring some stuff