Refactor several parts